package creation_patterns.factory_method_pattern.concrete_factory;

import creation_patterns.factory_method_pattern.abstract_product.Food;
import creation_patterns.factory_method_pattern.concrete_product.Bun;
import creation_patterns.factory_method_pattern.factory.FoodFactory;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class BunFactory implements FoodFactory {
//    可扩展性 相当于是一个对象多个引用
    public List<Food> bunBeanList = new CopyOnWriteArrayList<>();

    @Override
    public Food createFoodBean() {
        if(bunBeanList.isEmpty()){
            bunBeanList.add(new Bun());
        }
        return bunBeanList.get(0);
    }
}
